<template>
  <div 
    :class="[
      'bx-steps',
      `bx-steps--${direction}`,
      `bx-steps--${size}`
    ]"
  >
    <div 
      v-for="(step, index) in steps"
      :key="index"
      :class="[
        'bx-step',
        {
          'bx-step--active': index === current,
          'bx-step--finished': index < current,
          'bx-step--error': step.status === 'error',
          'bx-step--disabled': step.disabled
        }
      ]"
    >
      <!-- 步骤图标 -->
      <div class="bx-step__head">
        <div class="bx-step__icon bx-glass">
          <BxIcon 
            v-if="step.status === 'error'"
            name="x"
            class="bx-step__icon-content"
          />
          <BxIcon 
            v-else-if="index < current"
            name="check"
            class="bx-step__icon-content"
          />
          <BxIcon 
            v-else-if="step.icon"
            :name="step.icon"
            class="bx-step__icon-content"
          />
          <span 
            v-else
            class="bx-step__icon-content"
          >
            {{ index + 1 }}
          </span>
        </div>
        
        <!-- 连接线 -->
        <div 
          v-if="index < steps.length - 1"
          class="bx-step__line"
        ></div>
      </div>

      <!-- 步骤内容 -->
      <div class="bx-step__content">
        <div class="bx-step__title">
          {{ step.title }}
        </div>
        <div 
          v-if="step.description"
          class="bx-step__description"
        >
          {{ step.description }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BxIcon from '../basic/BxIcon.vue'

export default {
  name: 'BxSteps',
  components: {
    BxIcon
  },
  props: {
    current: {
      type: Number,
      default: 0
    },
    direction: {
      type: String,
      default: 'horizontal',
      validator: (value) => ['horizontal', 'vertical'].includes(value)
    },
    size: {
      type: String,
      default: 'medium',
      validator: (value) => ['small', 'medium', 'large'].includes(value)
    },
    steps: {
      type: Array,
      default: () => [],
      validator: (steps) => {
        return steps.every(step => 
          typeof step === 'object' && 
          typeof step.title === 'string'
        )
      }
    }
  },
  emits: ['change'],
  setup(props, { emit }) {
    const handleStepClick = (index, step) => {
      if (step.disabled) return
      emit('change', index)
    }

    return {
      handleStepClick
    }
  }
}
</script>

<style scoped>
.bx-steps {
  display: flex;
  font-family: var(--bx-font-family);
}

.bx-steps--horizontal {
  flex-direction: row;
  align-items: flex-start;
}

.bx-steps--vertical {
  flex-direction: column;
  align-items: stretch;
}

.bx-step {
  position: relative;
  flex: 1;
  display: flex;
  transition: all var(--bx-transition-medium);
}

.bx-steps--horizontal .bx-step {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.bx-steps--vertical .bx-step {
  flex-direction: row;
  align-items: flex-start;
  text-align: left;
  margin-bottom: var(--bx-spacing-lg);
}

.bx-steps--vertical .bx-step:last-child {
  margin-bottom: 0;
}

.bx-step__head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bx-steps--horizontal .bx-step__head {
  flex-direction: column;
  margin-bottom: var(--bx-spacing-md);
}

.bx-steps--vertical .bx-step__head {
  flex-direction: column;
  margin-right: var(--bx-spacing-md);
  align-items: center;
}

.bx-step__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--bx-glass-border);
  border-radius: 50%;
  background: var(--bx-glass-bg);
  backdrop-filter: var(--bx-glass-blur);
  transition: all var(--bx-transition-medium);
  position: relative;
  z-index: 1;
}

.bx-steps--small .bx-step__icon {
  width: 24px;
  height: 24px;
}

.bx-steps--large .bx-step__icon {
  width: 40px;
  height: 40px;
}

.bx-step__icon-content {
  color: var(--bx-text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.bx-steps--small .bx-step__icon-content {
  font-size: 12px;
}

.bx-steps--large .bx-step__icon-content {
  font-size: 16px;
}

.bx-step--active .bx-step__icon {
  border-color: rgba(0, 122, 255, 0.5);
  background: rgba(0, 122, 255, 0.15);
}

.bx-step--active .bx-step__icon-content {
  color: rgba(0, 122, 255, 0.9);
}

.bx-step--finished .bx-step__icon {
  border-color: rgba(52, 199, 89, 0.5);
  background: rgba(52, 199, 89, 0.15);
}

.bx-step--finished .bx-step__icon-content {
  color: rgba(52, 199, 89, 0.9);
}

.bx-step--error .bx-step__icon {
  border-color: rgba(255, 59, 48, 0.5);
  background: rgba(255, 59, 48, 0.15);
}

.bx-step--error .bx-step__icon-content {
  color: rgba(255, 59, 48, 0.9);
}

.bx-step--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bx-step__line {
  position: absolute;
  background: var(--bx-glass-border);
  transition: all var(--bx-transition-medium);
}

.bx-steps--horizontal .bx-step__line {
  top: 50%;
  left: 100%;
  width: 100%;
  height: 1px;
  transform: translateY(-50%);
}

.bx-steps--vertical .bx-step__line {
  top: 100%;
  left: 50%;
  width: 1px;
  height: var(--bx-spacing-lg);
  transform: translateX(-50%);
}

.bx-step--finished .bx-step__line {
  background: rgba(52, 199, 89, 0.5);
}

.bx-step__content {
  flex: 1;
}

.bx-steps--vertical .bx-step__content {
  padding-top: 4px;
}

.bx-step__title {
  color: var(--bx-text-primary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 4px;
}

.bx-steps--small .bx-step__title {
  font-size: 13px;
}

.bx-steps--large .bx-step__title {
  font-size: 16px;
}

.bx-step--active .bx-step__title {
  color: rgba(0, 122, 255, 0.9);
}

.bx-step--finished .bx-step__title {
  color: var(--bx-text-primary);
}

.bx-step--error .bx-step__title {
  color: rgba(255, 59, 48, 0.9);
}

.bx-step__description {
  color: var(--bx-text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.bx-steps--small .bx-step__description {
  font-size: 11px;
}

.bx-steps--large .bx-step__description {
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .bx-steps--horizontal {
    flex-direction: column;
  }
  
  .bx-steps--horizontal .bx-step {
    flex-direction: row;
    align-items: flex-start;
    text-align: left;
    margin-bottom: var(--bx-spacing-md);
  }
  
  .bx-steps--horizontal .bx-step:last-child {
    margin-bottom: 0;
  }
  
  .bx-steps--horizontal .bx-step__head {
    flex-direction: column;
    margin-right: var(--bx-spacing-md);
    margin-bottom: 0;
  }
  
  .bx-steps--horizontal .bx-step__line {
    top: 100%;
    left: 50%;
    width: 1px;
    height: var(--bx-spacing-md);
    transform: translateX(-50%);
  }
  
  .bx-steps--horizontal .bx-step__content {
    padding-top: 4px;
  }
}
</style>

